package com.fx.single.web;

import com.fx.single.model.AjqkDTO;
import com.fx.single.model.JjqkDTO;
import com.fx.single.repo.SingleRepo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

/**
 * 短信发送历史
 */
@Controller
@RequestMapping("/single")
@Slf4j
public class SingleController {
    private static Logger logger = LoggerFactory.getLogger(SingleController.class);

    @Value("${jjqk}")
    private int jjqk;

    @Value("${ajqk}")
    private int ajqk;

    @Value("${delay}")
    private int delay;

    @Resource
    private SingleRepo singleRepo;

    @RequestMapping(value = "/page")
    public String msgHistoryPage() {
        return "/single";
    }

    @GetMapping("/getAjqk")
    @ResponseBody
    public AjqkDTO getAjqk() {
        if(ajqk < 0 || ajqk > 24) {
            logger.error("配置错误: {ajqk}", ajqk);
        }
        return singleRepo.getAjqk(ajqk);
    }

    @GetMapping("/getJjqk")
    @ResponseBody
    public JjqkDTO getJjqk() {
        if(jjqk < 0 || jjqk > 24) {
            logger.error("配置错误: {jjqk}", jjqk);
        }
        return singleRepo.getJjqk(ajqk);
    }

    @GetMapping("/getDelay")
    @ResponseBody
    public int getDelay() {
        return delay;
    }
}